<!DOCTYPE html>
<html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>修改密码--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
    <link href="/resource/js/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="/resource/js/bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">
    <link href="/resource/css/table.css" rel="stylesheet" type="text/css">
</head>
<style>
</style>
<body style="background-color: #ecf0f5;font-family: 楷体;color: #475059;overflow: auto">
<div class="notice_main ">
    <div class="notice_check" style="padding: 16px 15px 8px 15px">
        <p>
            <label class="">订单编号：</label>
            <input type="text" id="uuId" class="find_input">
            <button class="check_btn" id="search">查询</button>
        </p>
        <div class="notice_nav r_right">
            <a class="btn btn-default addOrder"><span class="glyphicon glyphicon-plus"></span>生成订单</a>
        </div>
        <div class="clear"></div>
    </div>
    <table id="orderTables" class="orderTables" lay-filter="orderTables"></table>
</div>
<script type="text/html" id="operate">
    {{# if(d.status == '待发货' && d.mode !='自取'){ }}
    <a class="toolbarMy" lay-event="deliver">发货</a>
    {{# } else if(d.status == '待收货'&& d.mode !='自取'){ }}
    <a class="toolbarMy" lay-event="addLogistics">添加物流信息</a>
    <a class="toolbarMy" lay-event="lookLogistics">查看物流信息</a>
    {{# } else if(d.status == '待发货' && d.mode =='自取'){ }}
    <a class="toolbarMy" lay-event="deliver">客户已取货</a>
    {{# } else if(d.status == '退货成功'){ }}
    <a class="toolbarMy" lay-event="del">删除订单</a>
    {{# } else if(d.status != '退货中'){ }}
    <a class="toolbarMy" lay-event="saleReturn">退款</a>
    {{# } }}
</script>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript">
    var reminds;
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            laydate = layui.laydate,
            form = layui.form;
        table.render({
            elem: '#orderTables'
            , url: '/order/orderTable.do' //数据接口
            , method: 'get'
            , page: true //开启分页
            , id: 'tableId'
            , limits: [10, 15, 30]
            , limit: 15
            , cols: [
                [ //表头
                    {field: 'uuId', title: '订单编号', 'fixed': 'left'}
                    , {field: 'address', title: '收货信息', width: 400}
                    , {field: 'timestamp', title: '交易时间'}
                    , {field: 'price', title: '总价'}
                    , {field: 'status', title: '订单状态'}
                    , {field: 'remind', title: '发货提醒'}
                    , {field: 'mode', title: '配送方式'}
                    , {field: 'content', title: '备注'}
                    , {title: '操作', toolbar: '#operate', width: 180, 'fixed': 'right'}
                ]
            ]
        });
        //搜索
        $('#search').on('click', function () {
            active.reload()
        });
        //查看提醒消息
        reminds = function (id, time) {
            layer.msg("用户提醒发货,时间:" + time.substring(0, 19), {
                time: 0 //不自动关闭
                , btn: ['知道了']
                , yes: function (index) {
                    layer.close(index);
                    $.ajax({
                        url: "/order/delRemind.do",
                        type: "post",
                        data: {_method: "DELETE", "orderId": id},
                        dataType: "json",
                        success: function (result) {
                            if (!result.status) {
                                layer.msg(result.msg, {time: 2000});
                                return false;
                            }
                            active.reload();
                        }
                    });
                }
            });
        }
        //监听工具条
        table.on('tool(orderTables)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'deliver') {
                //发货
                editStatus(data.id, "待收货")
            } else if (obj.event === 'addLogistics') {
                layer.open({
                    type: 2,
                    title: "添加物流信息",
                    shadeClose: false, //点击遮罩关闭层
                    area: ['700px', '208px'],
                    content: "/order/addLogisticsPage.do?orderId=" + data.id
                });
            } else if (obj.event === 'lookLogistics') {
                layer.open({
                    type: 2,
                    title: "查看物流",
                    shadeClose: false, //点击遮罩关闭层
                    area: ['700px', '400px'],
                    content: "/order/lookLogistics.do?orderId=" + data.id
                });
            } else if (obj.event === "del") {
                del(data.id)
            } else if (obj.event === "saleReturn") {
                layer.open({
                    type: 2,
                    title: "退款",
                    shadeClose: false, //点击遮罩关闭层
                    area: ['700px', '600px'],
                    content: "/front/salesReturnPage.do?orderId=" + data.id
                });
            }
        });

        //生成订单
        $('.addOrder').on('click', function () {
            layer.open({
                type: 2,
                title: "生成订单",
                shadeClose: false, //点击遮罩关闭层
                area: ['700px', '400px'],
                content: "/order/salePage.do"
            });
        })

        //删除函数
        function del(id) {
            layer.confirm('是否删除?(删除订单影响数据统计)', function (index) {
                $.ajax({
                    url: "/order/order.do",
                    type: "post",
                    data: {_method: "DELETE", "id": id},
                    dataType: "json",
                    success: function (result) {
                        if (!result.status) {
                            layer.msg(result.msg, {time: 2000});
                            return false;
                        }
                        layer.msg("删除成功!", {time: 1000});
                        active.reload();
                    }
                });
                layer.close(index);
            })
        }

        //更改订单状态函数
        function editStatus(id, status) {
            $.ajax({
                url: "/order/order.do",
                type: "put",
                data: {"id": id, "status": status},
                dataType: "json",
                success: function (result) {
                    if (!result.status) {
                        layer.msg(result.msg, {time: 2000});
                        return false;
                    }
                    layer.msg("操作成功", {time: 1000});
                    active.reload();
                }
            });
        }

        active = {
            reload: function () {
                var uuId = $("#uuId").val();
                //执行重载
                table.reload('tableId', {
                    url: '/order/orderTable.do'
                    , method: 'get'
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        uuId: uuId,
                    }
                });
            }
        };
    });
</script>

</body>
</html>